package com.study.utils;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

/**
 * @desc:
 * @author: panxiyi
 * @date: 2023/5/3 11:54 下午
 */

@Component
public class MsgCodeUtils {

    public static final String[] patch = {"00000", "0000", "000", "00", "0", ""};

    public String generator(String tele) {
        int hash = tele.hashCode();
        long encryption = 202305036666L;
        long result = hash ^ encryption;
        long nowTime = System.currentTimeMillis();
        result = result ^ nowTime;
        long code = result % 100000;
        if (code < 0) {
            code = -code;
        }
        int len = String.valueOf(code).length();
        String strCode = patch[len - 1] + code;

        return strCode;
    }

    @Cacheable(value = "msgCode", key = "#tele")
    public String getMsgCode(String tele) {
        return null;
    }
//
//    public static void main(String[] args) {
//        System.out.println(generator("17850396698"));
//    }

}
